/* !点击logo回到首页 */
let logoimg = document.querySelector('.logoimg');
logoimg.onclick = () => {
  location.href = '../html/huaindex.html';
}

/* !ajax请求数据 */
ajax({
  url: '/flo/flowerlist.json',
  success: function (res) {
    res = JSON.parse(res);
    loveflo(res.loverlists);
    elder(res.elderlists);
    forever(res.foreverlists);
    cake(res.cakelists);
  }
})
/* ！爱情鲜花 */
function loveflo(data) {
  let lovelists = document.querySelector('.lovelists');
  lovelists.innerHTML = data.map((item) => {
    return `<li>
              <a href="../html/details.html?id=${item.ItemCode}">
              <div class="floimg"><img src="${item.url}" alt=""></div>
                   <p>爱情 · ${item.Cpmc}</p>
                  <span>￥${item.Price}</span>
                   <i>已售${item.Sales}</i>
              </a>
         </li>`
  }).join('')
}
/* !送长辈鲜花 */
function elder(data) {
  let elderlists = document.querySelector('.elderlists');
  elderlists.innerHTML = data.map((item) => {
    return `<li>
              <a href="../html/details.html?id=${item.ItemCode}">
              <div class="elderimg"><img src="${item.url}" alt=""></div>
                   <p>送长辈 · ${item.Cpmc}</p>
                  <span>￥${item.Price}</span>
                   <i>已售${item.Sales}</i>
              </a>
         </li>`
  }).join('');
}
/* !永生花 */
function forever(data) {
  let foreverlists = document.querySelector('.foreverlists');
  foreverlists.innerHTML = data.map((item) => {
    return `<li>
              <a href="../html/details.html?id=${item.ItemCode}">
              <div class="foreverimg"><img src="${item.url}" alt=""></div>
                   <p>永生花 · ${item.Cpmc}</p>
                  <span>￥${item.Price}</span>
                   <i>已售${item.Sales}</i>
              </a>
         </li>`
  }).join('');
}
/* !蛋糕 */
function cake(data) {
  let cakelists = document.querySelector('.cakelists');
  cakelists.innerHTML = data.map((item) => {
    return `<li>
              <a href="../html/details.html?id=${item.ItemCode}">
              <div class="cakeimg"><img src="${item.url}" alt=""></div>
                   <p>${item.Cpmc}</p>
                  <span>￥${item.Price}</span>
                   <i>已售${item.Sales}</i>
              </a>
         </li>`
  }).join('');
}

/* !热门资讯 */
ajax({
  url: "/flo/hotdata.json",
  success: function (res) {
    res = JSON.parse(res);
    hot(res.list);
  }
})
function hot(data) {
  let hotinfo_b = document.querySelector('.hotinfo_b');
  hotinfo_b.innerHTML = data.map((item) => {
    return ` <li>
                  <span></span>
                  <a href="">${item}</a>
            </li>`
  }).join('');
}

/* !二级导航 */
ajax({
  url: '/flo/types.json',
  success: function (res) {
    res = JSON.parse(res);
    forl(res.foreverleibie);
    forf(res.foreverperson);
    cakepinpai(res.cakepinpai);
    lp1(res.presonpinpai);
    lp2(res.presonleibie);
  }
});
function forl(data) {
  let foreverl = document.querySelector('.foreverl');
  foreverl.innerHTML = data.map((item) => {
    return `
    <li>
    <img src="${item.img}" alt="">
    <p>${item.name}</p>
     </li>`
  }).join('');
}
function forf(data) {
  let foreverf = document.querySelector('.foreverf');
  foreverf.innerHTML = data.map((item) => {
    return `
    <li>
    <img src="${item.img}" alt="">
    <p>${item.name}</p>
     </li>`
  }).join('');
};
function cakepinpai(data) {
  let cakep = document.querySelector('.cakep');
  cakep.innerHTML = data.map((item) => {
    return `
    <li>
    <img src="${item.img}" alt="">
    <p>${item.name}</p>
     </li>`
  }).join('');
}
function lp1(data) {
  let lipin1 = document.querySelector('.lipin1');
  lipin1.innerHTML = data.map((item) => {
    return `
    <li>
    <img src="${item.img}" alt="">
    <p>${item.name}</p>
     </li>`
  }).join('');
};
function lp2(data) {
  let lipin2 = document.querySelector('.lipin2');
  lipin2.innerHTML = data.map((item) => {
    return `
    <li>
    <img src="${item.img}" alt="">
    <p>${item.name}</p>
     </li>`
  }).join('');
}

/* !点击回顶部 */
let totop = document.querySelector('.totop');
totop.onclick = function (e) {
  scrollTo({
    top: 0,
    behavior:'smooth'
  })
}
/* !导航条固定 */
window.onscroll = function (e) {
   e = e || window.event;
  let y = scrollY;
  let fixnav = document.querySelector('.fixnav');
  if (y >= 700) {
    fixnav.style.position = 'fixed';
  } else {
     fixnav.style.position = 'absolute';
  }
}

let denglu = document.querySelector('.denglu');
denglu.onclick = (() => {
  /* !判断是否有login */
let login = getCookie('login');
if (login) {
    alert('您已经登录啦');
    return
} 
  location.href = '../html/login.html';
})
